﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="Account_Default" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:Panel ID="panelUserInfo" runat="server" GroupingText="User infomation">
        Sex:
        <asp:RadioButton ID="rbMale" runat="server" Text="Male" GroupName="sexGroup" Checked="true" />
        <asp:RadioButton ID="rbFemale" runat="server" Text="Female" GroupName="sexGroup" /><br />
        Age:<asp:TextBox ID="tbAge" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tbAge"
            ValidationGroup="A" ErrorMessage="*" Display="Dynamic" /><br />
        Height(cm):<asp:TextBox ID="tbHight" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tbHight"
            ValidationGroup="A" ErrorMessage="*" Display="Dynamic" /><br />
        Weight(kg):<asp:TextBox ID="tbWeight" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tbWeight"
            ValidationGroup="A" ErrorMessage="*" Display="Dynamic" /><br />
        Weight target(kg):<asp:TextBox ID="tbTarget" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="tbTarget"
            ValidationGroup="A" ErrorMessage="*" Display="Dynamic" />
        <br />
        <asp:Button ID="btSubmitInfo" runat="server" Text="Submit" ValidationGroup="A" OnClick="btSubmitInfo_Click" />
    </asp:Panel>
    <table width="100%">
        <tr>
            <td>
                <asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="White"
                    BorderWidth="1px" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="190px"
                    NextPrevFormat="FullMonth" Width="350px" OnSelectionChanged="Calendar1_SelectionChanged"
                    OnDayRender="Calendar1_DayRender">
                    <DayHeaderStyle Font-Bold="True" Font-Size="8pt" />
                    <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" VerticalAlign="Bottom" />
                    <OtherMonthDayStyle ForeColor="#999999" />
                    <SelectedDayStyle BackColor="#333399" ForeColor="White" />
                    <TitleStyle BackColor="White" BorderColor="Black" BorderWidth="4px" Font-Bold="True"
                        Font-Size="12pt" ForeColor="#333399" />
                    <TodayDayStyle BackColor="#CCCCCC" />
                </asp:Calendar>
                <a href="Report.aspx">Report</a>
            </td>
            <td valign="top" align="center" width="40%">
                <asp:Panel ID="Panel1" runat="server">
                    <asp:Label ID="lbTarget" runat="server" BorderStyle="Dashed" Font-Size="Large" ForeColor="#009933"></asp:Label>
                </asp:Panel>
                <asp:LinkButton ID="lbUpdateTarget" runat="server" 
                    onclick="lbUpdateTarget_Click">Update target</asp:LinkButton>
                <br />
                <div runat="server" visible="false" id="divUpdateTarget">
                    Weight target(kg):<asp:TextBox ID="tbUpdateTarget" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="tbUpdateTarget"
                        ValidationGroup="u" ErrorMessage="*" Display="Dynamic" /><asp:Button ID="btUpdate"
                            ValidationGroup="u" runat="server" Text="Update" 
                        onclick="btUpdate_Click" /></div>
            </td>
        </tr>
    </table>
    <asp:Panel ID="panel" runat="server">
        <asp:DetailsView ID="DetailsViewUpdate" runat="server" Height="50px" Width="125px"
            DataSourceID="SqlDataSource1" AutoGenerateRows="False" DataKeyNames="Id" 
            onitemupdated="DetailsViewUpdate_ItemUpdated">
            <Fields>
                <asp:BoundField DataField="CalorieAbsorbed" HeaderText="CalorieAbsorbed" SortExpression="CalorieAbsorbed" />
                <asp:BoundField DataField="TimeExercise" HeaderText="TimeExercise (hr)" SortExpression="TimeExercise" />
                <asp:BoundField DataField="Weight" HeaderText="Weight (kg)" SortExpression="Weight" />
                <asp:BoundField DataField="WaterAbsorbed" HeaderText="WaterAbsorbed (cc)" SortExpression="WaterAbsorbed" />
                <asp:CommandField ShowEditButton="True" />
            </Fields>
        </asp:DetailsView>
        <asp:DetailsView ID="DetailsViewInsert" runat="server" Height="50px" Width="125px"
            DataSourceID="SqlDataSource1" Visible="False" AutoGenerateRows="False" DataKeyNames="Id"
            DefaultMode="Insert" OnItemInserted="DetailsViewInsert_ItemInserted">
            <Fields>
                <asp:TemplateField HeaderText="CalorieAbsorbed" 
                    SortExpression="CalorieAbsorbed">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CalorieAbsorbed") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("CalorieAbsorbed") %>'></asp:TextBox>
                         <asp:RequiredFieldValidator ID="RequiredFieldValidatorca" runat="server" ControlToValidate="TextBox1"
                            Display="Dynamic" ErrorMessage="Please enter the Calorie Absorbed" ValidationGroup="InsertFieldDetails"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("CalorieAbsorbed") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="TimeExercise (hr)" SortExpression="TimeExercise">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TimeExercise") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("TimeExercise") %>'></asp:TextBox>
                         <asp:RequiredFieldValidator ID="RequiredFieldValidatortt" runat="server" ControlToValidate="TextBox2"
                            Display="Dynamic" ErrorMessage="Please enter the Time Exercise" ValidationGroup="InsertFieldDetails"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("TimeExercise") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Weight (kg)" SortExpression="Weight">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Weight") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("Weight") %>'></asp:TextBox>
                         <asp:RequiredFieldValidator ID="RequiredFieldValidatorww" runat="server" ControlToValidate="TextBox3"
                            Display="Dynamic" ErrorMessage="Please enter the Weight" ValidationGroup="InsertFieldDetails"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label3" runat="server" Text='<%# Bind("Weight") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="WaterAbsorbed (cc)" 
                    SortExpression="WaterAbsorbed">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("WaterAbsorbed") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("WaterAbsorbed") %>'></asp:TextBox>
                         <asp:RequiredFieldValidator ID="RequiredFieldValidatorwa" runat="server" ControlToValidate="TextBox4"
                            Display="Dynamic" ErrorMessage="Please enter the Water Absorbed" ValidationGroup="InsertFieldDetails"></asp:RequiredFieldValidator>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label4" runat="server" Text='<%# Bind("WaterAbsorbed") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowInsertButton="true" ValidationGroup="InsertFieldDetails" />
            </Fields>
        </asp:DetailsView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            InsertCommand="INSERT INTO [Schedule] ([CalorieAbsorbed], [TimeExercise], [Weight], [WaterAbsorbed], [Date], [UserId]) VALUES (@CalorieAbsorbed, @TimeExercise, @Weight, @WaterAbsorbed, @Date, @UserId)"
            SelectCommand="SELECT * FROM [Schedule] WHERE [UserId]=@UserId AND [Date]=@date"
            UpdateCommand="UPDATE [Schedule] SET [CalorieAbsorbed] = @CalorieAbsorbed, [TimeExercise] = @TimeExercise, [Weight] = @Weight, [WaterAbsorbed] = @WaterAbsorbed WHERE [Id] = @Id">
            <DeleteParameters>
                <asp:Parameter Name="Id" Type="Int32" />
            </DeleteParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="Calendar1" Name="date" Type="DateTime" PropertyName="SelectedDate" />
                <asp:Parameter Name="UserId" Type="String" />
            </SelectParameters>
            <InsertParameters>
                <asp:Parameter Name="CalorieAbsorbed" Type="Int32" />
                <asp:Parameter Name="TimeExercise" Type="Decimal" />
                <asp:Parameter Name="Weight" Type="Decimal" />
                <asp:Parameter Name="WaterAbsorbed" Type="Int32" />
                <asp:ControlParameter ControlID="Calendar1" Name="date" Type="DateTime" PropertyName="SelectedDate" />
                <asp:Parameter Name="UserId" Type="String" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="CalorieAbsorbed" Type="Int32" />
                <asp:Parameter Name="TimeExercise" Type="Decimal" />
                <asp:Parameter Name="Weight" Type="Decimal" />
                <asp:Parameter Name="WaterAbsorbed" Type="Int32" />
                <asp:Parameter Name="Date" Type="DateTime" />
                <asp:Parameter Name="UserId" Type="String" />
                <asp:Parameter Name="Id" Type="Int32" />
            </UpdateParameters>
        </asp:SqlDataSource>
    </asp:Panel>
</asp:Content>
